package shuiyuqing.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.volley.VolleyError;
import com.whu.administrator.ws.R;
import com.whu.administrator.ws.UIHandler;

import inter.Delegate;
import shuiyuqing.network.GetWeather;

/**
 * Created by Administrator on 2016/3/31.
 */
public class WeatherActivity extends UIHandler.BaseActivity {

    TextView tv_temp;
    TextView tv_WD;
    TextView tv_WS;
    TextView tv_SD;
    TextView tv_WSE;

    // 获取天气信息
    Delegate getWeatherData = new Delegate() {
        @Override
        public void onResponse(String response) {
            if (!response.startsWith("{")) return;
            GetWeather.ResponseWeather responseWeather = JSON.parseObject(response, GetWeather.ResponseWeather.class);
            tv_temp.setText(responseWeather.getWeatherinfo().getTemp());
            tv_WD.setText(responseWeather.getWeatherinfo().getWD());
            tv_WS.setText(responseWeather.getWeatherinfo().getWS());
            tv_SD.setText(responseWeather.getWeatherinfo().getSD());
            tv_WSE.setText(responseWeather.getWeatherinfo().getWSE());

        }

        @Override
        public void onErrorResponse(VolleyError error) {

        }
    };

    GetWeather getWeather = new GetWeather();
    {
        getWeather.setDelegate(getWeatherData);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weather);
        initview();
        initdata();
    }

    private void initdata() {
        getWeather.get();
    }

    private void initview() {
        tv_temp = (TextView) findViewById(R.id.id_tv_temp);
        tv_WD = (TextView) findViewById(R.id.id_tv_WD);
        tv_WS = (TextView) findViewById(R.id.id_tv_WS);
        tv_SD = (TextView) findViewById(R.id.id_tv_SD);
        tv_WSE = (TextView) findViewById(R.id.id_tv_WSE);
    }
}
